package superuser

import (
	"NovelBook/logic/superuser"
	"NovelBook/utils/auth"
	"NovelBook/utils/response"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/redis/go-redis/v9"
)

func GetThroughput(c *gin.Context) {
	id_any, exit := c.Get(auth.SuperIDKey)
	if !exit || id_any.(uint) != 1 {
		response.Fail(c, http.StatusBadRequest, response.CodeTokenInvalid)
		return
	}

	Info, err := superuser.GetThroughputInfo()
	if err != nil {
		if err == redis.Nil {
			response.Fail(c, http.StatusBadRequest, response.CodeNoContent)
		} else {
			response.FailWithMsg(c, http.StatusServiceUnavailable, response.CodeSystemBusy, "try again")
		}
		return
	}
	response.Success(c, Info)
}
